<?php
/**
 * WSCORE Administrator
 * @author wsfuyibing <websearch@163.com>
 * @package [PATH]project/controller
 * @date 2013-12-23
 */
defined('WSCORE') || exit('Access-Denied');
/**
 * 公共类库
 */
class AdminController extends BaseController {
	/**
	 * 属性描述
	 * @access protected array $administrator, 管理员账号
	 */
	protected $administrator = array('uid' => 0);
	protected $_query_action_current = '';
	protected $wapi_uid = 1;
	public $layout = 'index';
	/**
	 * 管理员账号初始化
	 */
	public function init(){
		parent::init(); 
		$this->_query_action_current = I('g.q');
		$this->_query_action_current || $this->_query_action_current = 'r';
		// if ($this->administrator['uid'] == 0){
			// $_id = $this->getId(); if ($_id != 'site'){
				// $this->redirect(H('admin://site/login'));
			// }
		// }
	}
	
	/**
	 * 保护继承
	 */
	protected function adminDenied(){
		print 'Access Denied';
		print "\r\n";
		print __CLASS__.'://'.__FUNCTION__;
		exit;
	}
	/**
	 * 表单返回
	 */
	protected function wscform($p, $_log = false){
		/**
		* 参数转换
		*/
		if (is_bool($p)){
			if ($p){
				$p = array('errno' => 0, 'error' => '');
			} else {
				$p = array('errno' => 1, 'error' => 'Fail');
			}
		} else {
			is_array($p) || $p = array();
		}
		/**
		* 写入日志
		*/
		if ($_log){}
		/**
		* AJAX提交
		*/
		if (A('request')->getIsAjaxRequest()){
			header('content-type: text/javascript');
			wsc::isarr($p, 'errno', '>0') || $p['errno'] = 0;
			exit(json_encode($p, true));
		}
		/**
		* 接受参数
		* @param array $p, 返回内容
		*/
		$_ispost = I('v.REQUEST_METHOD') === 'POST';
		/**
		* IFRAME提交
		* @var string $_domain, 当前根域
		* @var string $_host, 当前主机全名
		* @var string $_html, 输出HTML内容
		*/
		$_domain = ''; $_host = I('v.HTTP_HOST'); if (preg_match("/\.([a-z0-9_\-]+)\.([a-z0-9_\-]+)$/i", $_host, $_match)){
			$_domain = $_match[1].'.'.$_match[2];
		}
		/**
		* HTML输出
		*/
		$json  = '{}'; if (count($p)){
		$json = json_encode($p, true); }
		$html  = '<!doctype html>';
		$html .= '<html>';
			$html .= '<head>';
				$html .= '<title>Form-Result</title>';
				$html .= '<meta charset="utf-8" />'; 
				$_domain && 
				$html .= '<script type="text/javascript">document.domain="'.$_domain.'";</script>';
			$html .= '</head>';
			$html .= '<body>';
				$html .= '<script type="text/javascript">';
					$html .= 'try{';
						$html .= 'parent.$.fn.wscform('.$json.')';
					$html .= '}catch(errp){';
						$html .= 'try{';
							$html .= '$.fn.wscform('.$json.')';
						$html .= '}catch(errc){window.location.reload()}';
					$html .= '}';
				$html .= '</script>';
			$html .= '</body>';
		$html .= '</html>'; exit($html);
	}
}